self
}
+ /// Set the source id for this dependency
+ pub fn source_id(mut self, id: SourceId) -> Dependency {
+ self.source_id = id;
+ self
+ }
+
+ /// Set the version requirement for this dependency
+ pub fn version_req(mut self, req: VersionReq) -> Dependency {
+ self.req = req;
+ self
+ }
+
/// Returns false if the dependency is only used to build the local package.
pub fn is_transitive(&self) -> bool { self.transitive }
pub fn is_optional(&self) -> bool { self.optional }
}
pub fn for_git(url: &Url, reference: &str, precise: Option<String>) -> SourceId {
- let mut id = SourceId::new(GitKind(reference.to_string()), url.clone());
- if precise.is_some() {
- id = id.with_precise(precise.unwrap());
- }
-
- id
+ SourceId::new(GitKind(reference.to_string()), url.clone())
+ .with_precise(precise)
}
pub fn for_registry(url: &Url) -> SourceId {
self.inner.precise.as_ref().map(|s| s.as_slice())
}
- pub fn with_precise(&self, v: String) -> SourceId {
+ pub fn with_precise(&self, v: Option<String>) -> SourceId {
SourceId {
inner: Arc::new(SourceIdInner {
- precise: Some(v),
+ precise: v,
.. (*self.inner).clone()
}),
}
use std::collections::HashMap;
+use std::mem;
use semver::Version;
use core::{Dependency, PackageId, SourceId};
use util::{CargoResult, human};
-/// Subset of a `Manifest`. Contains only the most important informations about a package.
+/// Subset of a `Manifest`. Contains only the most important informations about
+/// a package.
///
/// Summaries are cloned, and should not be mutated after creation
#[deriving(Show,Clone)]
pub fn get_features(&self) -> &HashMap<String, Vec<String>> {
&self.features
}
+
+ pub fn map_dependencies(mut self, f: |Dependency| -> Dependency) -> Summary {
+ let deps = mem::replace(&mut self.dependencies, Vec::new());
+ self.dependencies = deps.into_iter().map(f).collect();
+ self
+ }
}
impl PartialEq for Summary {
match opts.precise {
Some(precise) => {
sources.push(dep.get_source_id().clone()
- .with_precise(precise.to_string()));
+ .with_precise(Some(precise.to_string())));
}
None => {}
}
use flate2::reader::GzDecoder;
use core::source::{Source, SourceId};
-use core::{Package, MultiShell, Summary, Dependency};
+use core::{Package, MultiShell, Dependency};
use sources::PathSource;
use util::{CargoResult, human, internal, ChainError, Require};
use ops;
// implicitly converted to registry-based dependencies, so we rewrite those
// dependencies here.
let registry = try!(SourceId::for_central());
- let new_deps = pkg.get_dependencies().iter().map(|d| {
- if !d.get_source_id().is_path() { return d.clone() }
- Dependency::parse(d.get_name(), d.get_specified_req(), ®istry)
- .unwrap()
- .transitive(d.is_transitive())
- .features(d.get_features().to_vec())
- .default_features(d.uses_default_features())
- .optional(d.is_optional())
- }).collect::<Vec<_>>();
- let new_summary = Summary::new(pkg.get_package_id().clone(),
- new_deps,
- pkg.get_summary().get_features().clone());
+ let new_summary = pkg.get_summary().clone().map_dependencies(|d| {
+ if !d.get_source_id().is_path() { return d }
+ d.source_id(registry.clone())
+ });
let mut new_manifest = pkg.get_manifest().clone();
- new_manifest.set_summary(new_summary.unwrap());
+ new_manifest.set_summary(new_summary);
let new_pkg = Package::new(new_manifest,
&manifest_path,
pkg.get_package_id().get_source_id());
try!(repo.copy_to(actual_rev.clone(), &self.checkout_path));
- let source_id = self.source_id.with_precise(actual_rev.to_string());
+ let source_id = self.source_id.with_precise(Some(actual_rev.to_string()));
let path_source = PathSource::new(&self.checkout_path, &source_id);
self.path_source = Some(path_source);